//
//  DemoViewController.swift
//  NCRouterBus
//
//  Created by 张文晏 on 2018/10/17.
//  Copyright © 2018年 Newcoretech. All rights reserved.
//

import UIKit

class DemoViewController: UIViewController {

    @IBOutlet weak var moduleAResultLb: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        /// 设置hook 示例
        NCModuleRouterBus.setRouterHook(url: URL(string: "ModuleB://page/ModuleBViewController")) { url, params, onResult -> Bool in
            NCModuleRouterBus.route(to: URL(string: "ModuleA://page/ModuleAViewController"), vc: self, skipType: .push(animated: true), params: params, onResult: onResult)
            return false
        }
    }

    @IBAction func didPushToModuleA(_ sender: Any) {
        NCModuleRouterBus.route(to: URL(string: "ModuleA://page/ModuleAViewController"), vc: self, skipType: .push(animated: true), params: nil, onResult: nil)
    }

    @IBAction func didPresentToModuleB(_ sender: Any) {
        NCModuleRouterBus.route(to: URL(string: "ModuleB://page/ModuleBViewController"), vc: self, skipType: .present(animated: true, completion: nil), params: nil, onResult: nil)
    }

    @IBAction func didModuleAWithParamsResults(_ sender: Any) {
        let param: [String: Any] = ["name": "DemoViewController", "info": 100]
        NCModuleRouterBus.route(to: URL(string: "ModuleA://page/ModuleAViewController"), vc: self, skipType: .present(animated: true, completion: nil), params: param) { res in
            self.moduleAResultLb.text = res?["result"] as? String
        }
    }
}
